var vue = new Vue({
	el: "body",
	data: {
		type: [],
		like: [],
		flag: 0,
		choose: "choose"
	},
	created: function() {
		console.log(sessionStorage.getItem("username"));
		getType();
	},
	methods: {
		click: function(index) {
			if (this.type[index].choose == 0) {
				this.type[index].choose = 1;
			} else {
				this.type[index].choose = 0;
			}
		},
		goTo: function() {
			for (var i = 0; i < this.type.length; i++) {
				if (this.type[i].choose == 1) {
					this.like.push(this.type[i].type)
				}
			}
			//上传更新个人爱好话题
			setType();
		}
	}
});

function getType() {
	var token = sessionStorage.getItem("token");
	var appid = sessionStorage.getItem("appid");
	$.ajax({
		type: 'get',
		url: "http://v2.mashupcloud.cn/SQL/getType/",
		data: {
			appid: appid,
			token: token,
			name: 'getType'
		},
		success: function(json) {
			console.log("json==" + json);
			vue.type = JSON.parse(json)[2];
			console.log(vue.type)
		},
		error: function(json) {
			console.log("err:" + json);
		}
	});
}

function setType() {
	var token = sessionStorage.getItem("token");
	var appid = sessionStorage.getItem("appid");
	var username = sessionStorage.getItem("username");
	console.log(vue.like)
	$.ajax({
		type: 'get',
		url: "http://v2.mashupcloud.cn/SQL/setType/",
		data: {
			appid: appid,
			token: token,
			name: 'setType',
			_v1: "" + vue.like + "",
			_v2: username
		},
		success: function(json) {
			console.log("json==" + json);
			location.href = "../head/index.html";
		},
		error: function(json) {
			console.log("err:" + json);
		}
	});
}